import axiosServer from '@/api/request'
import type { IRole, IResponseData } from '@/utils/types'
/**
 * 操作员列表
 * @returns
 */
export const RequestManagerList = ({ pageNo = 1, pageSize = 5, username = '' }): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/manager/list',
		method: 'get',
		params: {
			pageNo,
			pageSize,
			username
		}
	})
}

/**
 * 角色列表
 */
export const RequestRoleList = (): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/system/roles',
		method: 'get'
	})
}

/**
 * 注册-带头像上传
 */
export const RequestRegister = (formData: FormData): Promise<IResponseData> => {
	return axiosServer({
		method: 'post',
		url: '/api/register',
		headers: { 'Content-Type': 'multipart/form-data' },
		data: formData
	})
}

/**
 * 删除账户
 */
export const RequestManagerDelete = (id: number): Promise<IResponseData> => {
	return axiosServer({
		method: 'get',
		url: '/api/manager/delete',
		params: {
			id
		}
	})
}

/**
 * 删除账户
 */
export const RequestManagerBatchDelete = (ids: string): Promise<IResponseData> => {
	return axiosServer({
		method: 'get',
		url: '/api/manager/batchdelete',
		params: {
			ids
		}
	})
}

/**
 * 修改账户
 */
export const RequestMangerUpdate = (manager: any): Promise<IResponseData> => {
	return axiosServer({
		method: 'put',
		url: '/api/manager/update',
		data: {
			id: manager.m_id,
			username: manager.username,
			nick: manager.nick,
			roleId: manager.role_id
		}
	})
}
/**
 * 操作员日志列表
 * @returns
 */
export const RequestManagerLogList = ({ pageNo = 1, pageSize = 5 }): Promise<IResponseData> => {
	return axiosServer({
		url: '/api/manager/syslog',
		method: 'get',
		params: {
			pageNo,
			pageSize
		}
	})
}

/**
 * 注册-带头像上传
 */
export const RequestManagerLogAdd = (content: string, nick: string, ip: string): Promise<IResponseData> => {
	return axiosServer({
		method: 'post',
		url: '/api/manager/syslog',
		data: {
			content,
			nick,
			ip
		}
	})
}

export const managerApi = {
	RequestManagerList,
	RequestRoleList,
	RequestRegister,
	RequestManagerDelete,
	RequestManagerBatchDelete,
	RequestMangerUpdate,
	RequestManagerLogAdd,
	RequestManagerLogList
}
